package com.shawn.model.vo;

import com.shawn.model.entity.UserInfo;
import com.shawn.model.mongo.Video;
import lombok.Data;
import org.apache.commons.lang3.RandomUtils;
import org.bson.types.ObjectId;
import org.springframework.beans.BeanUtils;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @author shawn
 * @date 2022年 12月 21日 15:30
 */
@Data
public class VideoBackendVo {
    private Integer id;
    private String nickname;
    private Long userId;//发布者id
    private Date createDate;//发布者id
    private String videoUrl;//视频地址
    private String picUrl;//封面图片地址
    private Integer reportCount;//视频地址
    private Integer likeCount;//视频地址
    private Integer commentCount;//视频地址
    private Integer forwardingCount;//视频地址
    private String state;//视频地址
    private Map<String,Object> totals;//视频地址

    public static VideoBackendVo init(Video video, UserInfo userInfo){
        VideoBackendVo vo = new VideoBackendVo();
        BeanUtils.copyProperties(video,vo);
        vo.setId(video.getVid().intValue());
        vo.setNickname(userInfo.getNickname());
        vo.setCreateDate(new Date(video.getCreated()));
        vo.setReportCount(RandomUtils.nextInt(1,10));
        vo.setForwardingCount(RandomUtils.nextInt(1,100));
        vo.setState(video.getSeeType().toString());
        Map<String,Object> map = new HashMap<>();
        map.put("title",video.getText());
        map.put("code",4);
        map.put("value",RandomUtils.nextInt(10,999));
        vo.setTotals(map);
        return vo;
    }
}
